/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package management;

import java.io.*;

/**
 *
 * @author Admin
 * 
 */
public class ReadFile extends Thread
{
    private IsFile isFile;
    private String path;

    public void setFile(IsFile isFile)
    {
        this.isFile = isFile;
    }

    public void setPath(String path)
    {
        this.path = path;
    }

    public ReadFile(IsFile isFile, String path)
    {
        this.isFile = isFile;
        this.path = path;
    }

    public ReadFile()
    {
        this(new IsFile(), "");
    }

    @Override
    public void run()
    {
        try
        {
            File file = new File(path);

            if(file.exists())
            {
                if(!file.isDirectory())
                {
                    DataInputStream dis = new DataInputStream(new FileInputStream(file));
                    int n = dis.available();

                    for(int i = 0; i < n; i++)
                    {
                        isFile.setByte(dis.readByte());
                    }

                    isFile.setEndFile(true);
                    dis.close();
                }
                else
                {
                    isFile.setEndFile(true);
                }
            }
            else
            {
                isFile.setEndFile(true);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}
